#pragma once

#include <pthread.h>

class CThread
{
friend void* ThreadRun(CThread* pstThread);
public:
  pthread_attr_t m_tThreadAttr;
  pthread_t m_tThread;
  bool m_bDetach;
  bool m_bStart;
	
public:
  CThread(bool bDetach = true);
  virtual ~CThread();
  
  bool Start();
  int Terminate();
  int Join();
  virtual int End(){return Terminate();}
  pthread_t GetThreadId(){return m_tThread;}
	
protected:
  virtual void Run()= 0;
  virtual bool OnStart(){return true;}
  virtual void OnEnd() {}
  virtual void OnDelete();
};
